'''
!/usr/bin/python3
 -*- coding: utf-8 -*-
 @Time    : 2018/8/14 19:39
 @Author  : Tommy
 @FileName: serializers.py
'''
from django.db.models import Q
from rest_framework import serializers
from article.models import Category, Article, Race
from users.models import UserProfile


# ArticlesSerializer 外键所对应的 模型序列化
class UserProfileSerializer(serializers.ModelSerializer):
    class Meta:
        model = UserProfile
        fields = ("author",)


# 文章详情序列化   views.py 调用
class ArticlesSerializer(serializers.ModelSerializer):
    class Meta:
        model = Article
        fields = "__all__"


# 赛事详情序列化   views.py 调用
class RacesSerializer(serializers.ModelSerializer):
    class Meta:
        model = Race
        fields = "__all__"


class CategorySerializer3(serializers.ModelSerializer):
    class Meta:
        model = Category
        fields = "__all__"


class ArticleCategorySerializer3(serializers.ModelSerializer):
    articals = ArticlesSerializer(many=True)

    class Meta:
        model = Category
        fields = "__all__"


class raceCategorySerializer3(serializers.ModelSerializer):
    races = RacesSerializer(many=True)

    class Meta:
        model = Category
        fields = "__all__"


class CategorySerializer2(serializers.ModelSerializer):
    categories = CategorySerializer3(many=True)

    class Meta:
        model = Category
        fields = "__all__"


class ArticleCategorySerializer2(serializers.ModelSerializer):
    articals = ArticlesSerializer(many=True)
    ategories = ArticleCategorySerializer3(many=True)

    class Meta:
        model = Category
        fields = "__all__"


class RaceCategorySerializer2(serializers.ModelSerializer):
    categories = raceCategorySerializer3(many=True)
    races = RacesSerializer(many=True)

    class Meta:
        model = Category
        fields = "__all__"


# 类别分类序列化   views.py 调用
class CategorySerializer(serializers.ModelSerializer):
    categories = CategorySerializer2(many=True)

    class Meta:
        model = Category
        fields = "__all__"


# 赛事分类序列化   views.py 调用
class RaceListSerializer(serializers.ModelSerializer):
    categories = RaceCategorySerializer2(many=True)
    races = RacesSerializer(many=True)

    class Meta:
        model = Category
        fields = "__all__"


# 文章分类列表序列化
class ArticleListSerializer(serializers.ModelSerializer):
    categories = CategorySerializer2(many=True)
    articles = ArticlesSerializer(many=True)

    class Meta:
        model = Category
        fields = "__all__"
